home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 6 / Night Owl's Shareware - PDSI-006 - Night Owl Corp (1990).iso / 001a / sendcom@.zip / SENDCOM.C < prev    next >
Text File  |  1991-10-10  |  3KB  |  119 lines

  1. #include <stdlib.h>
  2. #include <stdio.h>
  3. #include <sys\stat.h>
  4. #include <fcntl.h>
  5. #include <ctype.h>
  6. #include <dos.h>
  7. #include <string.h>
  8.  
  9. #define CR "\n\r"
  10. #define rs232 0x14
  11. #define writech 1
  12. #define mask 0x7f
  13.  
  14. #define DATA_READY 0
  15. #define OVERRUN 0x1
  16. #define PARITY 0x2
  17. #define FRAMING 0x8
  18. #define BRK 0x10
  19. #define HOLDEMPTY 0x20
  20. #define SHIFTEMPTY 0x40
  21. #define FAILED 0x80
  22.  
  23. union REGS regs;
  24.  
  25. int COMPORT,mode,fileflag;
  26. char commandline[255];
  27. char filter[80];
  28.  
  29. extern int ANSI;
  30. char *pcb_printf(char *);
  31.  
  32. /*::::::::::::::::::::::::[ DISPLAY SECURITY FILE ]::::::::::::::::::::*/
  33. display_file(char *filename){
  34.         FILE *fp;
  35.         char buffer[85];
  36.         int bufflen=80;
  37.         if((fp=fopen(filename,"r"))==NULL){
  38.             strcpy(commandline,filename);
  39.             strcat(commandline," was not found!");
  40.             sendstr(commandline);
  41.             exit(1);}
  42.         CRLF(1);
  43.         while((fgets(buffer,bufflen,fp))!=NULL){
  44.             if(!strcmp(filter,"")){
  45.                 sendstr(buffer);
  46.                 xmit('\r');}
  47.             else
  48.                 if(strstr(buffer,filter)){
  49.                     sendstr(buffer);
  50.                     xmit('\r');}
  51.         }
  52.         fclose(fp); }
  53.  
  54. /*:::::::::::::::::::::::[ Send CR LF ]:::::::::::::::::::::::::::*/
  55. CRLF(int cnt){
  56. int i;
  57.         for (i=0;i<cnt;i++){
  58.             xmit('\n');
  59.             xmit('\r');
  60.             printf("\n");    }}
  61.  
  62. /*::::::::::::::[ SEND ONE CHARACTER TO SERIAL PORT ]::::::::::::::*/
  63. xmit(char ch){
  64.         int flag;
  65.         regs.h.ah = writech;
  66.         regs.x.dx = COMPORT;
  67.         regs.h.al = ch;
  68.         int86(rs232,®s,®s);
  69.         flag =(regs.h.ah&FAILED);
  70.         if (flag!=0){
  71.             printf("  COM%d failed!  ",COMPORT+1);
  72.             exit(1);}
  73. }
  74.  
  75. /*::::::::::::::::::[ Send string to Com ]:::::::::::::::::::::::*/
  76. xmit_str(char *s){
  77.         while(*s != '\0'){
  78.                 xmit(*s);
  79.                 s++;        }}
  80.  
  81.  
  82. /*:::::::::::::::::::[ Send string to COM or CON ]::::::::::::::::::*/
  83. sendstr(char *s){
  84.         char *str;
  85.         str=pcb_printf(s);
  86.         xmit_str(str);
  87. }
  88. /*:::::::::::::::::::[ Get command line ]:::::::::::::::::::::::::::*/
  89. getcline(int cnt,char *argarray[]){
  90.         int i;
  91.         strcat(commandline,'\0');
  92.         for(i=2;i<cnt;i++){
  93.                 if(!strcmp(argarray[i],"/F")){
  94.                     fileflag=1;
  95.                     strcpy(commandline,argarray[i+1]);
  96.                     if(cnt>4) strcpy(filter,argarray[i+2]);
  97.                     else strcpy(filter,"");
  98.                     return;                }
  99.                 if(!strcmp(argarray[i],"CR"))
  100.                     strcat(commandline,CR);
  101.                 else {
  102.                     strcat(commandline,argarray[i]);
  103.                     strcat(commandline," ");        }}}
  104.  
  105. main(int argc,char *argv[]){
  106.         char ANSIMODE[5];
  107.         mode=0;
  108.         strcpy(ANSIMODE,getenv("AN"));
  109.         if((strcmp(ANSIMODE,"ON"))==0)
  110.             ANSI=1;
  111.         COMPORT =atoi(argv[1])-1;
  112.         memset(commandline,'\0',255);
  113.         getcline(argc,argv);
  114.         if (fileflag==1)
  115.             display_file(commandline);
  116.         else
  117.             sendstr(commandline);
  118. }
  119.